//
//  AppDelegate+Extend.m
//  tiot
//
//  Created by admin on 2019/11/18.
//  Copyright © 2019 Kangjiedeng. All rights reserved.
//

#import "AppDelegate+Notification.h"

@implementation AppDelegate (Notification)

#pragma mark - 注册远程推送
- (void)registerNotification:(UIApplication*)application{
//    if (@available(iOS 10.0, *)) {
//        UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
//        center.delegate = self;
//        // 申请权限
//        [center requestAuthorizationWithOptions:UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound completionHandler:^(BOOL granted, NSError * _Nullable error) {
//                    NSLog(@"申请权限granted = %d", granted);
//                    if (!error && granted) {
//                        NSLog(@"远程通知注册成功");
//                    } else {
//                        NSLog(@"远程通知注册失败error-%@", error);
//                    }
//                }];
//                
//                // 获取权限设置 可以获取到用户设定通知的信息
//          [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
//                    NSLog(@"settings = %@", settings);
//                }];
//    }
//    else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
//        [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge categories:nil]];
//    }
// 
//    // 注册远程通知，获得device Token
//    [[UIApplication sharedApplication] registerForRemoteNotifications];
}

//// 在AppDelegate的回调中会返回DeviceToken，需要在登录后上报给IM后台（例如网易，腾讯）
//-(void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
//{
//    if (![deviceToken isKindOfClass:[NSData class]]) return;
//    const unsigned *tokenBytes = [deviceToken bytes];
//     NSString *token = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
//                              ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
//                              ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
//                              ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
////    NSLog(@"DeviceToken:%@\n", token);
//    [MJUIUserDeFault setObject:token forKey:Push_DeviceToken];
//
//    //[TJSmartHomeBase updateApnsToken:deviceToken]; //上报给第三方推送
//}
//
////获取token失败
//- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
//    //NSLog(@"获取token失败 :%@",error);
//}

@end
